package com.appspot.zcmjqm.app.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import com.appspot.zcmjqm.app.model.category.ProductCategory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@Entity
public class Product implements Serializable {
	
	private static final long serialVersionUID = 7707143880620933288L;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Key key;
	private String title;
	private String description;
	private Double price;
	@ManyToOne
	private ProductCategory productCategory;
	
	@Override
	public int hashCode() {
		return Long.valueOf(this.key.getId()).hashCode();
	}
	@Override
	public String toString() {
		return Long.valueOf(this.key.getId()).toString();
	}
	
	public Key getKey() {
		return key;
	}
	public void setKey(Key key) {
		this.key = key;
	}
	@Transient
	public String getKeyString() {
		return KeyFactory.keyToString(key);
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	public ProductCategory getProductCategory() {
		return productCategory;
	}
	public void setProductCategory(ProductCategory productCategory) {
		this.productCategory = productCategory;
	}

}
